﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cow.Module;
using System.IO;
using System.CodeDom;

namespace Cow.Handler
{
    /// <summary>
    /// 生成仓储代码
    /// </summary>
    public class ExportRepositoryHandler : ExportFromCodeDom
    {
        public override string SuffixName
        {
            get { return "Repository"; }
        }

        protected override CodeNamespace CreateCode(Design design)
        {
            CodeNamespace codeNamespace = new CodeNamespace(design.NameSpace);
            // 添加命名空间
            codeNamespace.Imports.Add(new CodeNamespaceImport("System"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.ComponentModel"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.ComponentModel.DataAnnotations"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.Linq"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.Runtime.Serialization"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.ServiceModel.DomainServices.Server"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.Text"));
            // 创建类
            CodeTypeDeclaration exportClass = new CodeTypeDeclaration(design.ModuleName + "Repository");
            //接口
            exportClass.BaseTypes.Add(new CodeTypeReference("I" + design.ModuleName + "Repository"));
            codeNamespace.Types.Add(exportClass);
            return codeNamespace;
        }
    }
}
